﻿using Architecture.API.Application.Command.UserInfoRoleCommand;
using Architecture.Domain.Dto.UserInfoRoleDto;
using Architecture.Domain.Service.UserInfoRoleServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.UserInfoRoleHandler
{
    /// <summary>
    /// 查询用户角色部门ID命令处理器
    /// </summary>
    public class UserInfoRoleSearchDepartmentIdCommandHandler : IRequestHandler<UserInfoRoleSearchDepartmentIdCommand, List<UserInfoRoleDepartmentDto>>
    {
        /// <summary>
        /// 用户角色服务
        /// </summary>
        private readonly IUserInfoRoleService _userInfoRoleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userInfoRoleService">用户角色服务</param>
        public UserInfoRoleSearchDepartmentIdCommandHandler(IUserInfoRoleService userInfoRoleService)
        {
            _userInfoRoleService = userInfoRoleService;
        }

        /// <summary>
        /// 处理查询用户角色部门ID命令
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回结果</returns>
        public async Task<List<UserInfoRoleDepartmentDto>> Handle(UserInfoRoleSearchDepartmentIdCommand request, CancellationToken cancellationToken)
        {
            return await _userInfoRoleService.GetDepartmentByRoleId(request.RoleId);
        }
    }
}
